package personal.study.bl;

import java.sql.Connection;
import java.util.Collection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import personal.study.db.DBTransaction;
import personal.study.form.TransactionForm;
import personal.study.util.DBConnection;

public class BLTransactionAction {
	private static Log log = LogFactory.getLog(BLTransactionAction.class);

	public int getCount(String conditions) throws Exception{
		int count = 0;
		Connection con = null;
		try{
			con = DBConnection.getCon();
			DBTransaction dbTransaction = new DBTransaction();
			count = dbTransaction.getCount(con, conditions);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return count;
	}
	
	public Collection<TransactionForm> findByTransCode(String conditions, int currentPage, int rowsPerPage) throws Exception{
		Collection<TransactionForm> col = null;
		Connection con = null;
		try{
			con = DBConnection.getCon();
			DBTransaction dbTransaction = new DBTransaction();
			col = dbTransaction.findByTransCode(con, conditions, currentPage, rowsPerPage);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return col;
	}
	
	public Collection<TransactionForm> findByConditions(String conditions) throws Exception{
		Collection<TransactionForm> col = null;
		Connection con = null;
		try{
			con = DBConnection.getCon();
			DBTransaction dbTransaction = new DBTransaction();
			col = dbTransaction.findByConditions(con, conditions);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return col;
	}
	
	public boolean update(TransactionForm transactionForm) throws Exception{
		boolean result = false;
		Connection con = null;
		try{
			con = DBConnection.getCon();
			DBTransaction dbTransaction = new DBTransaction();
			result = dbTransaction.update(con, transactionForm);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return result;
	}
}
